package com.snda.sc.web;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

import com.snda.sc.utils.Logs;

/**
 * 禁用HTTP缓存过滤器。
 * 
 * @author <a href="mailto:seenoevil.cn@gmail.com">李曦</a><br/>
 *         Created at: 2012-10-3 下午1:03:55
 */
public class ForbidCacheFilter implements Filter {

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
			ServletException {
		Logs.updateVersion();

		HttpServletResponse resp = (HttpServletResponse) response;
		resp.setHeader("Cache-Control", "no-cache");
		resp.setHeader("Connection", "close");
		resp.setHeader("Pragma", "no-cache");
		resp.setDateHeader("Expires", -1);

		chain.doFilter(request, response);
	}

	@Override
	public void destroy() {
	}
}
